package com.sea.supply.service.impl;



import com.sea.physical.entity.CreateDespatchSku;
import com.sea.supply.entity.WareDistribute;
import com.sea.supply.entity.WareProduce;
import com.sea.supply.mapper.WareDistributeMapper;
import com.sea.supply.service.*;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class WareDistributeServiceImpl implements WareDistributeService {

    @Autowired
    private WareDistributeMapper wareDistributeMapper;
    @Autowired
    private ReceiveService receiveService;
    @Autowired
    private ProduceDetailService produceDetailService;
    @Autowired
    private SupplierService supplierService;

    @Override
    public Integer save(WareDistribute wareDistribute) {
        return wareDistributeMapper.insert(wareDistribute);
    }

    @Override
    public Integer save(WareProduce wareProduce) {
        //查询是否存在国内仓
        WareDistribute wareDistribute = findReceiveNumber(wareProduce);
        WareDistribute distribute=new WareDistribute();
        if(null==wareDistribute){

            BeanUtils.copyProperties(wareProduce,distribute);
            return save(distribute);
        }else{

            wareDistribute.setReceiveNumber(wareDistribute.getReceiveNumber()+wareProduce.getReceiveNumber());
            return usave(wareDistribute);

        }
    }


    @Override
    public WareDistribute findReceiveNumber(WareProduce wareProduce) {
        return wareDistributeMapper.findReceiveNumber(wareProduce);
    }

    @Override
    public Integer usave(WareDistribute wareDistribute) {
        return wareDistributeMapper.update(wareDistribute);
    }

    @Override
    public Integer updateUseNumber(Integer useNumber, Integer id) {
        return wareDistributeMapper.updateUseNumber(useNumber, id);
    }

    @Override
    public List<WareDistribute> getDistributeNumber(String receiveSku, String receiveChannelName) {
        return wareDistributeMapper.getDistributeNumber(receiveSku,receiveChannelName);
    }

    @Override
    public WareDistribute findById(Integer id) {
        return wareDistributeMapper.findById(id);
    }

    @Override
    public List<WareDistribute> findByCnd(WareDistribute wareDistribute) {
        return wareDistributeMapper.findByCnd(wareDistribute);
    }

    @Override
    public WareDistribute findBySkuChannelNo(WareDistribute wareDistribute) {
        return wareDistributeMapper.findBySkuChannelNo(wareDistribute);
    }

    @Override
    public List<WareDistribute> findByDistributeReadyUse(String receiveSku, String receiveChannelName) {
        return wareDistributeMapper.findByDistributeReadyUse(receiveSku, receiveChannelName);
    }

    @Override
    public Integer updateReadyUseNumber(Integer useReadyNumber, Integer id) {
        return wareDistributeMapper.updateReadyUseNumber(useReadyNumber, id);
    }
}
